// #include <Windows.h>
// #include <iostream>
// #include <string>
// #include "shortcut.h"
// #include "stringhelper.h"
// #include <filesystem>
// #include "encoding.h"

// extern "C"
// {
//     __declspec(dllexport) bool __cdecl CWaitProcessExit(int pid, int *pExitCode);
//     __declspec(dllexport) bool __cdecl CCreateShortcut(char *szSourcePath, char *szShortcutPath, char *szStartDir, char *szDescription, char *szIconPath);
//     __declspec(dllexport) void __cdecl CPrintHello()
//     {
//         std::cout << "Hello." << std::endl;
//     }
//     __declspec(dllexport) void __cdecl CPrintLine(char *arg)
//     {
//         std::cout << arg << std::endl;
//     }

//     bool CCreateShortcut(char *szSourcePath, char *szShortcutPath, char *szWorkDirectory, char *szDescription, char *szIconPath)
//     {
//         const auto sourcePath = processmonitor::Utf8ToGbk(szSourcePath);
//         const auto shortcutPath = processmonitor::Utf8ToGbk(szShortcutPath);
//         const auto workDirectory = processmonitor::Utf8ToGbk(szWorkDirectory);
//         const auto description = processmonitor::Utf8ToGbk(szDescription);
//         const auto iconPath = processmonitor::Utf8ToGbk(szIconPath);

//         std::cout << "begain create shortcut..." << std::endl;
//         std::cout << "sourcePath: " << sourcePath << std::endl;
//         std::cout << "shortcutPath: " << sourcePath << std::endl;
//         std::cout << "workDirectory: " << workDirectory << std::endl;
//         std::cout << "description: " << description << std::endl;
//         std::cout << "iconPath: " << iconPath << std::endl;

//         processmonitor::Shortcut shortcut;
//         shortcut.sourcePath = (char *)sourcePath.c_str();
//         shortcut.shortcutPath = (char *)shortcutPath.c_str();
//         shortcut.workDirectory = (char *)workDirectory.c_str();
//         shortcut.description = (char *)description.c_str();
//         shortcut.iconPath = (char *)iconPath.c_str();

//         auto result = processmonitor::CreateShortcut(shortcut);

//         std::cout << "create shortcut is " << (result ? "succeed." : "failed.") << std::endl;

//         return result;
//     }

//     bool CWaitProcessExit(int pid, int *pExitCode)
//     {
//         HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

//         if (hProcess)
//         {
//             std::cout << "wait process " << pid << " exit..." << std::endl;
//             ::WaitForSingleObject(hProcess, INFINITE); // 阻塞直到进程退出
//             DWORD exitCode;
//             ::GetExitCodeProcess(hProcess, &exitCode);
//             std::cout << "process exit code: " << exitCode << std::endl;
//             ::CloseHandle(hProcess);

//             *pExitCode = exitCode;
//             return true;
//         }

//         std::cout << "open process " << pid << " failed." << std::endl;
//         return false;
//     }
// }
